<?php
class Category
{

    private $property = array();
    private $valid = false;

    private $valid_properties = "CategoryID,CategoryDescription";

    public static function createNew($id, $description)
    {
        $S = new Category();
        $S->CategoryID($id);
        $S->CategoryDescription($description);

        return $S;
    }

    public static function createFromArray($values)
    {
        if (!is_array($values)) return null;
        if (count($values) <= 0) return null;

        $S = new Category();
        $S->FromArray($values);
        return $S;
    }

    public function __construct()
    {

    }

    public function ID()
    {
        return $this->GetSetData("CategoryID",null);
    }
    
    public function CategoryDescription($value = null)
    {        
        return $this->GetSetData("CategoryDescription",$value);
    }

    public function StorableData()
    {
        $result["CategoryID"] = $this->UserLevelID();
        $result["CategoryDescription"] = $this->UserLevelDescription();

        return $result;
    }
    
    private function GetSetData($property_name,$value = null)
    {
        //if (!$this->checkPropertyName($property_name)) return null;

        if (is_null($value)) return $this->property[$property_name];
        $this->property[$property_name] = $value;
    }

    private function checkPropertyName($property_name)
    {
        foreach (explode(",",$this->valid_properties) as $allowed_prop)
            if ($allowed_prop == $property_name) return true;

        return false;
    }


    /*
     * Populate from an array
     */
    public function FromArray($values)
    {
        if (!is_array($values)) return null;

        foreach ($values as $key => $value)
            $this->GetSetData($key,$value);

    }


    public function __toString()
    {
        return print_r($this->property,true);
    }


}

?>
